package com.yawn.zerodefect.config;

import com.yawn.zerodefect.util.Constant;
import com.yawn.zerodefect.util.EncryptUtil;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.User;
import org.activiti.image.ProcessDiagramGenerator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Created by yawn on 2018-01-26 17:07
 */
@Service
public class DataInitService {

    @Resource
    private IdentityService identityService;
    @Resource
    private ProcessEngineConfiguration configuration;

    public void init() {

//        configuration.setDatabaseSchemaUpdate("drop-create");
//        configuration.buildProcessEngine();

        Group managerGroup = identityService.newGroup(Constant.GROUP_MANAGER);
        managerGroup.setName("管理员");
        identityService.saveGroup(managerGroup);
        Group requireGroup = identityService.newGroup(Constant.GROUP_REQUIRE);
        requireGroup.setName("需求组");
        identityService.saveGroup(requireGroup);
        Group testerGroup = identityService.newGroup(Constant.GROUP_TESTER);
        testerGroup.setName("测试组");
        identityService.saveGroup(testerGroup);
        Group developerGroup = identityService.newGroup(Constant.GROUP_DEVELOPER);
        developerGroup.setName("开发组");
        identityService.saveGroup(developerGroup);

        User admin = identityService.newUser("admin");
        admin.setPassword(EncryptUtil.md5Encrypt("123456"));
        admin.setFirstName("管理员");
        identityService.saveUser(admin);

        identityService.createMembership("admin", Constant.GROUP_MANAGER);
    }
}
